package com.zhcd.sys.controller;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhcd.sys.pojo.Mattess;
import com.zhcd.sys.service.MattessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author feifei
 * @since 2021-11-29
 */
@RestController
@RequestMapping("/sys/mattess")
public class MattessController {
    @Autowired
    public MattessService mattessService;

    //添加床垫
    @RequestMapping(value = "/ins_Mattess",method = RequestMethod.POST)
    @ResponseBody
    public String ins_Mattess(@RequestBody Map<String,Object> para) throws JsonProcessingException {
        Mattess mattess = (Mattess)para.get("mattess");
        HashMap<String,Object> hs=new HashMap<>();
        hs.put("code","200");
        hs.put("data",mattessService.ins_Mattess(mattess));
        ObjectMapper objectMapper=new ObjectMapper();
        return objectMapper.writeValueAsString(hs);
    }

    //查询全部
    @RequestMapping(value = "/selAll_Mattess",method = RequestMethod.GET)
    @ResponseBody
    public String selAll_Mattess() throws JsonProcessingException{
        HashMap<String,Object> hs=new HashMap<>();
        hs.put("code","200");
        hs.put("data",mattessService.selAll_Mattess());
        ObjectMapper objectMapper=new ObjectMapper();
        return objectMapper.writeValueAsString(hs);
    }

    //条件(设备号、床号)查询床垫信息
    @RequestMapping(value = "/selList_Mattess",method = RequestMethod.GET)
    @ResponseBody
    public String selList_Mattess(@RequestBody Map<String,Object> para) throws JsonProcessingException{
        String id = (String)para.get("id");
        HashMap<String,Object> hs=new HashMap<>();
        hs.put("code","200");
        hs.put("data",mattessService.selList_Mattess(id));
        ObjectMapper objectMapper=new ObjectMapper();
        return objectMapper.writeValueAsString(hs);
    }
    //删除床垫信息
    @RequestMapping(value = "/del_Mattess",method = RequestMethod.DELETE)
    @ResponseBody
    public String del_Mattess(@RequestBody Map<String,Object> para) throws JsonProcessingException{
        Integer id = (Integer)para.get("id");
        HashMap<String,Object> hs=new HashMap<>();
        hs.put("code","200");
        hs.put("data",mattessService.del_Mattess(id));
        ObjectMapper objectMapper=new ObjectMapper();
        return objectMapper.writeValueAsString(hs);
    }
    //修改床垫信息
    @RequestMapping(value = "/upd_Mattess",method = RequestMethod.POST)
    @ResponseBody
    public String upd_Mattess(@RequestBody Map<String,Object> para) throws JsonProcessingException{
        Mattess mattess = (Mattess)para.get("mattess");
        HashMap<String,Object> hs=new HashMap<>();
        hs.put("code","200");
        hs.put("data",mattessService.upd_Mattess(mattess));
        ObjectMapper objectMapper=new ObjectMapper();
        return objectMapper.writeValueAsString(hs);
    }
}

